

    function [output] = fourth_order_sigma_delta_ciff(X,bit_lev,vref,param_cfg)


        fixed_point_cfg = param_cfg.fixed_point_cfg;
        % C3 =  -0.024044;  c3 = -0.249725        C3 =  -0.024044;
        % C2 =  -0.212190;  c2 = -0.292645        C2 =  -0.212190;
        % C1 =   0.193228;  c1 = -1.073592        C1 =   0.193228;
        % A4 =   0.405751;  a4 = -0.906206        A4 =   0.105751;
        % A3 =  -0.212190;  a3 = 1.387099         A3 =  -0.112190;
        % A2 =   0.405739;  a2 = -1.073592        A2 =   0.255739;
        % A1 =   0.400700;  a1 = 1.592700         A1 =   0.650700;
        % b1   = fixed_point_calculation_vector(  0.92     , 1, 'mul' , fixed_point_cfg.Int_num , fixed_point_cfg.Fixed_num,fixed_point_cfg.DataType);
        % c3   = fixed_point_calculation_vector(  -0.249725 , 1, 'mul' , fixed_point_cfg.Int_num , fixed_point_cfg.Fixed_num,fixed_point_cfg.DataType);
        % c2   = fixed_point_calculation_vector(  -0.292645 , 1, 'mul' , fixed_point_cfg.Int_num , fixed_point_cfg.Fixed_num,fixed_point_cfg.DataType);
        % c1   = fixed_point_calculation_vector(  -1.073592 , 1, 'mul' , fixed_point_cfg.Int_num , fixed_point_cfg.Fixed_num,fixed_point_cfg.DataType);
        % a4   = fixed_point_calculation_vector(  -0.906206 , 1, 'mul' , fixed_point_cfg.Int_num , fixed_point_cfg.Fixed_num,fixed_point_cfg.DataType);
        % a3   = fixed_point_calculation_vector(  1.387099  , 1, 'mul' , fixed_point_cfg.Int_num , fixed_point_cfg.Fixed_num,fixed_point_cfg.DataType);
        % a2   = fixed_point_calculation_vector(  -1.073592 , 1, 'mul' , fixed_point_cfg.Int_num , fixed_point_cfg.Fixed_num,fixed_point_cfg.DataType);
        % a1   = fixed_point_calculation_vector(  1.592700  , 1, 'mul' , fixed_point_cfg.Int_num , fixed_point_cfg.Fixed_num,fixed_point_cfg.DataType);
        % X    = fixed_point_calculation_vector(X           , 1, 'mul' , fixed_point_cfg.Int_num , fixed_point_cfg.Fixed_num,fixed_point_cfg.DataType);
        % vref = fixed_point_calculation_vector(vref        , 1, 'mul' , fixed_point_cfg.Int_num , fixed_point_cfg.Fixed_num,fixed_point_cfg.DataType);
        b1   = fixed_point_calculation_vector(  0.50     , 1, 'mul' , fixed_point_cfg.Int_num , fixed_point_cfg.Fixed_num,fixed_point_cfg.DataType);
        c3   = fixed_point_calculation_vector(  0.05 , 1, 'mul' , fixed_point_cfg.Int_num , fixed_point_cfg.Fixed_num,fixed_point_cfg.DataType);
        c2   = fixed_point_calculation_vector(  0.25 , 1, 'mul' , fixed_point_cfg.Int_num , fixed_point_cfg.Fixed_num,fixed_point_cfg.DataType);
        c1   = fixed_point_calculation_vector(  0.30 , 1, 'mul' , fixed_point_cfg.Int_num , fixed_point_cfg.Fixed_num,fixed_point_cfg.DataType);
        a4   = fixed_point_calculation_vector(  0.10 , 1, 'mul' , fixed_point_cfg.Int_num , fixed_point_cfg.Fixed_num,fixed_point_cfg.DataType);
        a3   = fixed_point_calculation_vector(  0.11 , 1, 'mul' , fixed_point_cfg.Int_num , fixed_point_cfg.Fixed_num,fixed_point_cfg.DataType);
        a2   = fixed_point_calculation_vector(  0.45 , 1, 'mul' , fixed_point_cfg.Int_num , fixed_point_cfg.Fixed_num,fixed_point_cfg.DataType);
        a1   = fixed_point_calculation_vector(  0.55 , 1, 'mul' , fixed_point_cfg.Int_num , fixed_point_cfg.Fixed_num,fixed_point_cfg.DataType);
        X    = fixed_point_calculation_vector(X           , 1, 'mul' , fixed_point_cfg.Int_num , fixed_point_cfg.Fixed_num,fixed_point_cfg.DataType);
        vref = fixed_point_calculation_vector(vref        , 1, 'mul' , fixed_point_cfg.Int_num , fixed_point_cfg.Fixed_num,fixed_point_cfg.DataType);

        dataLen = length(X);

%         v1 = zeros(1, dataLen);      % First integrator output
%         v2 = zeros(1, dataLen);      % Second integrator output
%         v3 = zeros(1, dataLen);      % Third integrator output
%         v4 = zeros(1, dataLen);      % Fourth integrator output
%         y  = zeros(1, dataLen);
        Yprev = 0;

        persent_prev = -1;
        for n = 1 : dataLen

            if(n > 1)
                % v1(n) = X(n-1)*b1 - Yprev + v1(n-1);
                % v2(n) = v1(n-1) * c1   + v2(n-1);
                % v3(n) = v2(n-1) * c2   + v3(n-1);
                % v4(n) = v3(n-1) * c3   + v4(n-1);
                v1(n) = fixed_point_calculation_vector(X(n-1)*b1 - (Yprev) + v1(n-1) , 1, 'mul' , fixed_point_cfg.Int_num , fixed_point_cfg.Fixed_num,fixed_point_cfg.DataType);
                % if v1(n) > 1
                %     v1(n) = 1;
                % end
                % if v1(n) < -1
                %     v1(n) = -1;
                % end
                v2(n) = fixed_point_calculation_vector(v1(n-1) * c1   + v2(n-1)    , 1, 'mul' , fixed_point_cfg.Int_num , fixed_point_cfg.Fixed_num,fixed_point_cfg.DataType);
                % if v2(n) > 1
                %     v2(n) = 1;
                % end
                % if v2(n) < -1
                %     v2(n) = -1;
                % end
                v3(n) = fixed_point_calculation_vector(v2(n-1) * c2   + v3(n-1)    , 1, 'mul' , fixed_point_cfg.Int_num , fixed_point_cfg.Fixed_num,fixed_point_cfg.DataType);
                % if v3(n) > 1
                %     v3(n) = 1;
                % end
                % if v3(n) < -1
                %     v3(n) = -1;
                % end
                v4(n) = fixed_point_calculation_vector(v3(n-1) * c3   + v4(n-1)    , 1, 'mul' , fixed_point_cfg.Int_num , fixed_point_cfg.Fixed_num,fixed_point_cfg.DataType);
                % if v4(n) > 10
                %     v4(n) = 10;
                % end
                % if v4(n) < -10
                %     v4(n) = -10;
                % end
            else
                % v1(n) = X(n)*b1 - Yprev + 0;
                % v2(n) = v1(n) * c1   + 0;
                % v3(n) = v2(n) * c2   + 0;
                % v4(n) = v3(n) * c3   + 0;
                v1(1) = X(1);
                v2(1) = X(1);
                v3(1) = X(1);
                v4(1) = X(1);
            end

            % y(n)  = a1* v1(n) + a2*v2(n) + a3*v3(n) + a4*v4(n)  ;
            y(n)  = fixed_point_calculation_vector(a1* v1(n) + a2*v2(n) + a3*v3(n) + a4*v4(n) , 1, 'mul' , fixed_point_cfg.Int_num , fixed_point_cfg.Fixed_num,fixed_point_cfg.DataType);
            % if y(n) > 1
            %     y(n) = 1;
            % end
            % if y(n) < -1
            %     y(n) = -1;
            % end

            % output_step = (2*vref) / (2^(bit_lev)-1);
            % output_step = fixed_point_calculation_vector((2*vref) / (2^(bit_lev)-1)  , 1, 'mul' , fixed_point_cfg.Int_num , fixed_point_cfg.Fixed_num,fixed_point_cfg.DataType);
            output_step = fixed_point_calculation_vector((2*vref)   , (2^(bit_lev)-1), 'div' , fixed_point_cfg.Int_num , fixed_point_cfg.Fixed_num,fixed_point_cfg.DataType);

            % output(n) = round(y(n) / output_step);
            output(n) = fixed_point_calculation_vector(round(y(n) / output_step), 1, 'mul' , fixed_point_cfg.Int_num , fixed_point_cfg.Fixed_num,fixed_point_cfg.DataType);
            if(output(n) > (2^(bit_lev-1) -1) )
                output(n) = 2^(bit_lev-1) -1;
            end
            if(output(n) < (-(2^(bit_lev-1) -1)) )
                output(n) = -(2^(bit_lev-1)-1);
            end

            % Yprev = output(n)*output_step;
            Yprev = fixed_point_calculation_vector(output(n)   , output_step, 'mul' , fixed_point_cfg.Int_num , fixed_point_cfg.Fixed_num,fixed_point_cfg.DataType);
            e(n) = y(n)-Yprev;
            if(e(n) >= 1 || e(n) <= -1)
                e(n) = e(n);
            end


            persent = fix(n/dataLen*100);
            if(mod(persent,1)==0)

                if(persent_prev ~= persent)
                    %clc;
                    fprintf("sdm处理中,进度%02d %%.\n",persent);
                end
            end
            persent_prev = persent;
        end

        if(param_cfg.debug.sdm_internal_sig == "enable")
            figure;
            plot(v1);
            title(' V1');
            xlabel(' V1');
            grid on;

            figure;
            plot(v2);
            title(' V2');
            xlabel(' V2');
            grid on;

            figure;
            plot(v3);
            title(' V3');
            xlabel(' V3');
            grid on;

            figure;
            plot(v4);
            title(' V4');
            xlabel(' V4');
            grid on;

            figure;
            plot(X);
            title(' X');
            xlabel(' X');
            grid on;

            figure;
            plot(output);
            title(' OUTPUT');
            xlabel(' OUTPUT');
            grid on;

            figure;
            plot(e);
            title(' E');
            xlabel(' E');
            grid on;
        end

    end

